package com.neo.tiny.admin.service.sys.impl;

import cn.hutool.core.collection.CollUtil;
import com.neo.tiny.admin.entity.sys.SysUserRole;
import com.neo.tiny.admin.mapper.sys.SysUserRoleMapper;
import com.neo.tiny.admin.service.sys.SysPermissionService;
import com.neo.tiny.query.LambdaQueryWrapperBase;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @Description: 权限 Service 实现类
 * @Author: yqz
 * @CreateDate: 2022/10/16 10:21
 */
@Service
@AllArgsConstructor
public class SysPermissionServiceImpl implements SysPermissionService {


    private final SysUserRoleMapper userRoleMapper;


    @Override
    public Set<Long> getUserRoleIdListByRoleIds(Collection<Long> roleIds) {

        List<SysUserRole> userRoles = userRoleMapper.selectList(new LambdaQueryWrapperBase<SysUserRole>()
                .eq(SysUserRole::getRoleId, roleIds));
        if (CollUtil.isEmpty(userRoles)) {
            return new HashSet<>();
        }
        return userRoles.stream().map(SysUserRole::getUserId).filter(Objects::nonNull)
                .collect(Collectors.toSet());
    }
}
